package com.dslcode.cloud.shop.api.controller;

import com.dslcode.cloud.common.api.order.OrderAPI;
import com.dslcode.cloud.common.dto.order.OrderCreateDTO;
import com.dslcode.cloud.common.dto.order.OrderDetailDTO;
import com.dslcode.cloud.common.dto.order.OrderPayDTO;
import com.dslcode.cloud.common.model.order.Order;
import com.dslcode.cloud.common.utils.AjaxResponse;
import com.dslcode.cloud.shop.api.feign.OrderProviderFeign;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by dongsilin on 2017/9/21.
 */
@Slf4j
@RestController
public class OrderController implements OrderAPI {

    @Autowired
    private OrderProviderFeign orderProviderFeign;

    @Override
    public AjaxResponse<PageInfo<OrderPayDTO>> list(@RequestParam(name = "pageNum", defaultValue = "1") int pageNum, @RequestParam(name = "pageSize", defaultValue = "10") int pageSize){
        return orderProviderFeign.list(pageNum, pageSize);
    }

    @Override
    public AjaxResponse<OrderDetailDTO> detail(@PathVariable(name = "id") Long id){
        return orderProviderFeign.detail(id);
    }

    @Override
    public AjaxResponse<Order> create(@RequestBody OrderCreateDTO orderCreate, @RequestParam(name = "userId", defaultValue = "1") Long userId){
        return orderProviderFeign.create(orderCreate, userId);
    }

}
